<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>

    <body>
        <form id="importExcelForm" class="import-file-form" enctype="multipart/form-data">
            <input type="file" name="excelFile" id="excelFile" style="width:160px" value="选择文件">
            <input class="fabu_button_e margin-right-20" type="button" value="导入" inited=" " onclick="submitExcel(); ">
            <div id="error" style="color:#ff0000;"></div>
        </form>
    <br>
        <a href="#" style="text-decoration:underline;">请下载模板</a>
        <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
        <script type="text/javascript">
            function submitExcel() {
                var formData = new FormData($("#importExcelForm")[0]);
                $.ajax({
                    url: '/excelFileUpload',
                    data: formData,
                    type: 'post',
                    dataType: 'json',
                    cache: false,
                    contentType: false,//这里
                    processData: false,//这两个一定设置为false
                    success: function (data) {
                        if (data.flag == '1') {
                            window.$dialog.hide(data);
                        }
                        if (data.flag == '0') {
                            //回写error信息到弹框页面
                            alert("excel填写有误,请检查,错误信息为" + data.error);
                        }
                    }
                });
            }

        </script>
    </body>
</html>